package view.gui {	
	import controller.ControllerManager;
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.SimpleButton;
	import flash.events.MouseEvent;
	import view.graph.GraphStates;
	import view.graph.states.GraphExpansionType;
	import view.GraphicPost;
	import view.ressources.GraphicRessources;
	/**
	 * ...
	 * @author Anthony
	 */
	public class GraphicPostGui
	{
		//------------------------------- statics ------------------------------\\
		
		//------------------------------ variables -----------------------------\\
		private var _graphicPostTarget						: GraphicPost;
		
		private var _goToNextGraphicPostBrotherButton 		: SimpleButton;
		private var _goToPreviousGraphicPostBrotherButton 	: SimpleButton;
		
		//------------------------------ accessors -----------------------------\\
		public function get goToNextGraphicPostBrotherButton() 		: SimpleButton { return _goToNextGraphicPostBrotherButton; }
		public function get goToPreviousGraphicPostBrotherButton() 	: SimpleButton { return _goToPreviousGraphicPostBrotherButton; }
		
		//-------------------------- public functions --------------------------\\
		public function GraphicPostGui(graphicPostTarget : GraphicPost)
		{
			_graphicPostTarget = graphicPostTarget;
			
			_goToNextGraphicPostBrotherButton = new SimpleButton(	new Bitmap(GraphicRessources.self.goToNextGraphicPostBrotherButton), 
																	new Bitmap(GraphicRessources.self.goToNextGraphicPostBrotherButton_OVER),
																	new Bitmap(GraphicRessources.self.goToNextGraphicPostBrotherButton), 
																	new Bitmap(GraphicRessources.self.goToNextGraphicPostBrotherButton));
			_goToNextGraphicPostBrotherButton.addEventListener(MouseEvent.CLICK, onGoToNextGraphicPostBrotherButtonClick);
			_goToNextGraphicPostBrotherButton.x = _graphicPostTarget.graphic.width - (GraphicRessources.self.goToNextGraphicPostBrotherButton.width / 2);													
			_graphicPostTarget.guiContainer.addChild(_goToNextGraphicPostBrotherButton);
																	
			_goToPreviousGraphicPostBrotherButton = new SimpleButton(	new Bitmap(GraphicRessources.self.goToPreviousGraphicPostBrotherButton), 
																		new Bitmap(GraphicRessources.self.goToPreviousGraphicPostBrotherButton_OVER),
																		new Bitmap(GraphicRessources.self.goToPreviousGraphicPostBrotherButton), 
																		new Bitmap(GraphicRessources.self.goToPreviousGraphicPostBrotherButton));
			_goToPreviousGraphicPostBrotherButton.addEventListener(MouseEvent.CLICK, onGoToPreviousGraphicPostBrotherButtonClick);
			_goToPreviousGraphicPostBrotherButton.x = -GraphicRessources.self.goToPreviousGraphicPostBrotherButton.width / 2;
			_graphicPostTarget.guiContainer.addChild(_goToPreviousGraphicPostBrotherButton);
		}
		
		public function update() : void
		{
			if (GraphStates.self.graphExpansionType == GraphExpansionType.CONDENSED)
			{
				_graphicPostTarget.graphic.addEventListener(MouseEvent.MOUSE_OVER, onOverGraphicPost);
				
				_goToNextGraphicPostBrotherButton.visible = false;
				_goToPreviousGraphicPostBrotherButton.visible = false;
			}
			else if (GraphStates.self.graphExpansionType == GraphExpansionType.EXTENDED)
			{
				_graphicPostTarget.graphic.removeEventListener(MouseEvent.MOUSE_OVER, onOverGraphicPost);
				
				var graphicPostTargetIndexInBrotherArray : Number = _graphicPostTarget.graphicAnswerOf.graphicAnswers.indexOf(_graphicPostTarget);
				if (graphicPostTargetIndexInBrotherArray == 0)
					_goToPreviousGraphicPostBrotherButton.visible = false;
				else
					_goToPreviousGraphicPostBrotherButton.visible = true;
					
				if (graphicPostTargetIndexInBrotherArray == (_graphicPostTarget.graphicAnswerOf.graphicAnswers.length - 1))
					_goToNextGraphicPostBrotherButton.visible = false;
				else
					_goToNextGraphicPostBrotherButton.visible = true;					
			}
		}
				
		//------------------------- private functions --------------------------\\
		private function onOverGraphicPost(e : MouseEvent) : void
		{
			ControllerManager.self.onOverGraphicPost(_graphicPostTarget);
		}
		
		private function onGoToNextGraphicPostBrotherButtonClick(e : MouseEvent) : void
		{
			ControllerManager.self.goToNextBrother(_graphicPostTarget);
		}
		
		private function onGoToPreviousGraphicPostBrotherButtonClick(e : MouseEvent) : void
		{
			ControllerManager.self.goToPreviousBrother(_graphicPostTarget);
		}
		
	}	
}